const router = require("koa-router")();
const UserModel = require("../../models/users");
router.post("/api/login", async ctx => {
    var { username, psd } = ctx.request.body;
    var data = await UserModel.find();
    var u = data[0]._doc.username;
    var p = data[0]._doc.psd;
    var id = data[0]._doc._id;
    if (username == u && psd == p) {
        // 设置缓存,并且设置前端可读
        ctx.cookies.set('loginAuth', true, {
            httpOnly: false //前端可读
        });
        ctx.cookies.set('userID', id, {
            httpOnly: false //前端可读
        });
        ctx.body = {
            code: 200,
            res: data,
            msg: `登录成功！`
        }
    } else {
        ctx.body = {
            code: 400,
            msg: "用户名或密码错误"
        }
    }

})
module.exports = router;